# albumcontroller.py
from pysage import Actor, ActorManager
from messages import *
import logging

omanager = ActorManager.get_singleton()

class AlbumController(Actor):
    '''responsible for album related logic'''
    subscriptions = ['RemoveAlbumMessage']
    def view_album(self, index):
        albumid = omanager.find('mapi').get_albumids()[index]
        logging.debug('albumcontroller: switching album to %s'  % albumid)
        omanager.queue_message(AlbumSelectedMessage(albumid = albumid))
        omanager.queue_message_to_group('resource_loading', AlbumSelectedMessage(albumid = albumid))
        return True
    def close(self):
        omanager.queue_message(CloseApplicationMessage())
        return True
    def right_mouse_up(self, index):        
        # if the user actually right-clicked on an album, then we want to pop up a menu
        albumid = omanager.find('mapi').get_albumids()[index]
        omanager.trigger(AlbumPopUpMenuMessage(albumid = albumid))
        return True
    def edit_album_users(self, albumid, users):
        return omanager.find('mapi').edit_album_users(albumid, users)
    def handle_RemoveAlbumMessage(self, msg):
        omanager.find('mapi').remove_album(msg.get_property('albumid'))
        omanager.queue_message(InitializeAlbumsViewerMessage())
        return False
        
        
                
